﻿using BXH.Movie.Bll;
using BXH.Movie.Model;
using CCWin;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace BXH.Movie.FrmAdmin
{
    public partial class FrmMovieSessionAdd : CCWin.CCSkinMain
    {

        MovieSessionService movieSessionService = new MovieSessionService();
        MovieInfoService movieInfoService = new MovieInfoService();
        public event EventHandler AddSuccess;
        public FrmMovieSessionAdd()
        {
            InitializeComponent();
        }

        private void FrmMovieSessionAdd_Load(object sender, EventArgs e)
        {
            var movies = movieInfoService.GetMovieInfos();
            cbxMovieName.DataSource = movies;
            cbxMovieName.DisplayMember = "Name";
        }

        private void btnAdd_Click(object sender, EventArgs e)
        {
            var movie = cbxMovieName.SelectedItem as MovieInfoDto;
            var model = new Model.MovieSession();
            try
            {
                var date = DateTime.Parse(dtpTime.text);
                var time = DateTime.Parse(txtStartTime.Text);
                var dateTimeStr = $"{date.Date.ToString("yyyy-MM-dd")} { time.ToString("HH:mm:ss")}";
                var dateTime = Convert.ToDateTime(dateTimeStr);

                model.BroadcastTime = dateTime;
                model.MovieId = movie.Id;
            }
            catch (Exception ex)
            {
                MessageBoxEx.Show("日期格式不正确");
                return;
            }
            movieSessionService.Add(model);
            AddSuccess?.Invoke(this,null);
            this.Close();

        }
    }
}
